import * as types from '../mutations'

import http from '../../http'

const state = {
    vm:'',
    user_list: [],
    total: '',
    user_detail: ''
}

const getters = {
    user_list: state => state.user_list,
    total: state => state.total,
    user_detail: state => state.user_detail,
}

const mutations = {
    [types.SET_VM] : (state,payload) => {
        state.vm = payload.vm
    },
    [types.SET_USER_LIST]: (state, payload) => {
        state.user_list = payload
    },
    [types.SET_TOTAL]: (state, payload) => {
        state.total = payload
    },
    [types.SET_USER_DETAIL]: (state, payload) => {
        state.user_detail = payload
        console.log(payload)
    }
}

const actions = {
    query_user(context, payload) {
        http('/api/user/query_user', payload, res => {
            context.commit(types.SET_USER_LIST, res.data)
            context.commit(types.SET_TOTAL, res.object.total)
        })
    },
    user_detail(context, payload) {
        http('/api/user/user_detail', payload, res => {
            context.commit(types.SET_USER_DETAIL, res.object.user)
        })
    }
}

export default {
    state,
    getters,
    mutations,
    actions

}

